package com.dawnClass.controller;


import com.dawnClass.pojo.Consumer;
import com.dawnClass.pojo.LearningRate;
import com.dawnClass.service.LearningRateService;
import com.dawnClass.util.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class learningRateController {

    @Autowired
    private LearningRateService learningRateService;

    @PostMapping("learn/video/leave")
    public void saveLearningRate(LearningRate learningRate ,
                                 HttpSession session){
        ServiceResponse serviceResponse = (ServiceResponse) session.getAttribute("ServiceResponse");
        Consumer consumer = (Consumer) serviceResponse.getdata();
        learningRate.setConsumerId(consumer.getConsumerId());
        //判断当前用户是否在当前课程存在学习进度，如果存在就修改学习不存在就新建
        System.out.println("用户本次学习记录:" + learningRate);
        learningRateService.saveRate(learningRate);
        System.out.println("用户已离开学习界面");
    }
}
